//
//  JudgeResultViewController.swift
//  LongTermInsurance
//
//  Created by zolobdz on 2018/11/24.
//  Copyright © 2018年 HeChao. All rights reserved.
//

import UIKit
import ObjectMapper
class JudgeResultViewController: BaseTableViewController {

//    lazy var headerView: MeHeaderView = {
//        let view = Bundle.main.loadNibNamed("MeHeaderView", owner: nil
//            , options: nil)!.last as! MeHeaderView
//        view.frame = CGRect(x: 0, y: 0, width: DeviceInfo.screenWidth, height: 120)
//        return view
//    }()
//
//    lazy var footerView: MyApplyResultView = {
//        let view = MyApplyResultView()
//        view.frame = CGRect(x: 0, y: 0, width: DeviceInfo.screenWidth, height: 600)
//        return view
//    }()
    
    lazy var dataSource = [JudgeResult]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "评估结果"
        // Do any additional setup after loading the view.
        view.backgroundColor = CDColor.grayBackgroundColorA
        tableView.register(JudgeResultCell.self, forCellReuseIdentifier: "JudgeResultCell")
        tableView.backgroundColor = CDColor.grayBackgroundColorA
//        tableView.tableHeaderView = headerView
//        tableView.tableFooterView = footerView
        tableView.rowHeight = 280.0
        tableView.separatorColor = .clear
        getData()
    }

    func getData() {
        
        guard let info = MyselfSingleton.shared.userInfo else{
            return
        }
        
        let json = ["PersionID": info.userID].convertToJsonString()
        let paramString = "<json>"+json+"</json>"
        CDUtility.showHud()
        NetworkingHandle.fetchNetworkData(method: "getAccessInfo", paramString: paramString, success: {[weak self] (dict) in
            CDUtility.hidHud()
            if let imgsString = dict["Detail"] as? String {
                if let array = Mapper<JudgeResult>().mapArray(JSONString: imgsString) {
                    self?.dataSource = array
                    self?.tableView.reloadData()
                }
            }
            if let code = dict["ResultCode"] as? Int,code == 1 {
                if let msgString = dict["ResultMessage"] as? String {
                    CDUtility.showMSG(message: msgString)
                }
            }
        }) {
            print("")
        }
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataSource.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "JudgeResultCell", for: indexPath) as! JudgeResultCell
        cell.config(model: dataSource[indexPath.row])
        return cell
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let model = dataSource[indexPath.row]
        UIManager.shared.showQRPage(qrString: "\(model.applyNum)")
    }
}
